﻿Imports System.Windows.Data
Imports System.Windows
Imports OMANE.Common.UI
Imports System.Windows.Input
Imports System.Windows.Media

Public Class EditZone
    Implements ICloneable


    Sub New()

        ' Cet appel est requis par le concepteur.
        InitializeComponent()

        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
        'VerticalAlignment = Windows.VerticalAlignment.Center
        'HorizontalAlignment = Windows.HorizontalAlignment.Center

        'Width = 300
        'Height = 300
    End Sub

    Public Property Selected As Boolean
        Get
            Return GetValue(SelectedProperty)
        End Get

        Set(ByVal value As Boolean)
            SetValue(SelectedProperty, value)
        End Set
    End Property

    Public Shared ReadOnly SelectedProperty As DependencyProperty = _
                           DependencyProperty.Register("Selected", _
                           GetType(Boolean), GetType(EditZone), _
                           New FrameworkPropertyMetadata(False))



    Public Property CornerRadius As Double
        Get
            Return GetValue(CornerRadiusProperty)
        End Get

        Set(ByVal value As Double)
            SetValue(CornerRadiusProperty, value)
        End Set
    End Property

    Public Shared ReadOnly CornerRadiusProperty As DependencyProperty = _
                           DependencyProperty.Register("CornerRadius", _
                           GetType(Double), GetType(EditZone), _
                           New FrameworkPropertyMetadata(0.0))




    Public Property BorderSize As Double
        Get
            Return GetValue(BorderSizeProperty)
        End Get

        Set(ByVal value As Double)
            SetValue(BorderSizeProperty, value)
        End Set
    End Property

    Public Shared ReadOnly BorderSizeProperty As DependencyProperty = _
                           DependencyProperty.Register("BorderSize", _
                           GetType(Double), GetType(EditZone), _
                           New FrameworkPropertyMetadata(0.0))





    Public Property TopRuler As UIElement
        Get
            Return GetValue(TopRulerProperty)
        End Get

        Set(ByVal value As UIElement)
            SetValue(TopRulerProperty, value)
        End Set
    End Property

    Public Shared ReadOnly TopRulerProperty As DependencyProperty = _
                           DependencyProperty.Register("TopRuler", _
                           GetType(UIElement), GetType(EditZone), _
                           New FrameworkPropertyMetadata(Nothing))

    Public Property BottomRuler As UIElement
        Get
            Return GetValue(BottomRulerProperty)
        End Get

        Set(ByVal value As UIElement)
            SetValue(BottomRulerProperty, value)
        End Set
    End Property

    Public Shared ReadOnly BottomRulerProperty As DependencyProperty = _
                           DependencyProperty.Register("BottomRuler", _
                           GetType(UIElement), GetType(EditZone), _
                           New FrameworkPropertyMetadata(Nothing))

    Public Property LeftRuler As UIElement
        Get
            Return GetValue(LeftRulerProperty)
        End Get

        Set(ByVal value As UIElement)
            SetValue(LeftRulerProperty, value)
        End Set
    End Property

    Public Shared ReadOnly LeftRulerProperty As DependencyProperty = _
                           DependencyProperty.Register("LeftRuler", _
                           GetType(UIElement), GetType(EditZone), _
                           New FrameworkPropertyMetadata(Nothing))

    Public Property RightRuler As UIElement
        Get
            Return GetValue(RightRulerProperty)
        End Get

        Set(ByVal value As UIElement)
            SetValue(RightRulerProperty, value)
        End Set
    End Property

    Public Shared ReadOnly RightRulerProperty As DependencyProperty = _
                           DependencyProperty.Register("RightRuler", _
                           GetType(UIElement), GetType(EditZone), _
                           New FrameworkPropertyMetadata(Nothing))

    Private Sub Thumb_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
        Dim o = TryCast(DataContext, VMDashboardDefinitionZone)
        If o Is Nothing Then Return

        'o.EditCommand.Execute(Nothing)

        Dim ui = ModuleIndicateurs.AppInstance.GetService(Of IUIService)()
        'GraphDefinition.DetailEdit = New VMEditableObject(GraphDefinition.DetailInstance)
        ui.ShowMessage(New EditZoneFacade(Me))
    End Sub

    Private Sub Thumb_DragDelta(ByVal sender As System.Object, ByVal e As System.Windows.Controls.Primitives.DragDeltaEventArgs)
        If Keyboard.Modifiers = ModifierKeys.Control Then
            Dim o = 1

            Dim rt = TryCast(Me.RenderTransform, RotateTransform)
            If rt Is Nothing Then
                Me.RenderTransformOrigin = New Point(0.5, 0.5)
                rt = New RotateTransform(0.0)
                Me.RenderTransform = rt
            End If

            rt.Angle += Math.Atan2(e.VerticalChange, e.HorizontalChange)

            Return
        End If

        If sender Is cbthumb Then
            cbthumbdrag(e.HorizontalChange, e.VerticalChange)
        End If
        If sender Is ctthumb Then
            ctthumbdrag(e.HorizontalChange, e.VerticalChange)
        End If
        If sender Is lcthumb Then
            lcthumbdrag(e.HorizontalChange, e.VerticalChange)
        End If
        If sender Is rcthumb Then
            rcthumbdrag(e.HorizontalChange, e.VerticalChange)
        End If
        If sender Is ccthumb Then
            ccthumbdrag(e.HorizontalChange, e.VerticalChange)
        End If
        If sender Is rotcenterthumb Then
            rotcenterthumbdrag(e.HorizontalChange, e.VerticalChange)
        End If
        If sender Is rotarrowthumb Then
            rotarrowthumbdrag(e.HorizontalChange, e.VerticalChange)
        End If


    End Sub

    Private Sub cbthumbdrag(ByVal HorizontalChange As Double, ByVal VerticalChange As Double)
        Select Case Me.VerticalAlignment
            Case Windows.VerticalAlignment.Center
                If Double.IsNaN(Height) Then
                    Height = ActualHeight
                End If
                Height += VerticalChange

            Case Windows.VerticalAlignment.Top
                Margin = New Thickness(Margin.Left, Margin.Top, Margin.Right, 0.0)
                If Double.IsNaN(Height) Then
                    Height = ActualHeight
                End If
                Height += VerticalChange

            Case Windows.VerticalAlignment.Bottom
                Margin = New Thickness(Margin.Left, Margin.Top, Margin.Right, Margin.Bottom - VerticalChange)
                If Double.IsNaN(Height) Then
                    Height = ActualHeight
                End If
                Height += VerticalChange

            Case Windows.VerticalAlignment.Stretch
                Margin = New Thickness(Margin.Left, Margin.Top, Margin.Right, Margin.Bottom - VerticalChange)

        End Select
    End Sub

    Private Sub ctthumbdrag(ByVal HorizontalChange As Double, ByVal VerticalChange As Double)
        Select Case Me.VerticalAlignment
            Case Windows.VerticalAlignment.Center
                If Double.IsNaN(Height) Then
                    Height = ActualHeight
                End If
                Height -= VerticalChange

            Case Windows.VerticalAlignment.Top
                Margin = New Thickness(Margin.Left, Margin.Top + VerticalChange, Margin.Right, Margin.Bottom)
                If Double.IsNaN(Height) Then
                    Height = ActualHeight
                End If
                Height -= VerticalChange

            Case Windows.VerticalAlignment.Bottom
                Margin = New Thickness(Margin.Left, 0.0, Margin.Right, Margin.Bottom)
                If Double.IsNaN(Height) Then
                    Height = ActualHeight
                End If
                Height -= VerticalChange

            Case Windows.VerticalAlignment.Stretch
                Margin = New Thickness(Margin.Left, Margin.Top + VerticalChange, Margin.Right, Margin.Bottom)

        End Select
    End Sub

    Private Sub lcthumbdrag(ByVal HorizontalChange As Double, ByVal VerticalChange As Double)
        Select Case Me.HorizontalAlignment
            Case Windows.HorizontalAlignment.Center
                If Double.IsNaN(Width) Then
                    Width = ActualWidth
                End If
                Width -= HorizontalChange

            Case Windows.HorizontalAlignment.Left
                Margin = New Thickness(Margin.Left + HorizontalChange, Margin.Top, Margin.Right, Margin.Bottom)
                If Double.IsNaN(Width) Then
                    Width = ActualWidth
                End If
                Width -= HorizontalChange

            Case Windows.HorizontalAlignment.Right
                Margin = New Thickness(0.0, Margin.Top, Margin.Right, Margin.Bottom)
                If Double.IsNaN(Width) Then
                    Width = ActualWidth
                End If
                Width -= HorizontalChange

            Case Windows.HorizontalAlignment.Stretch
                Margin = New Thickness(Margin.Left + HorizontalChange, Margin.Top, Margin.Right, Margin.Bottom)

        End Select
    End Sub

    Private Sub rcthumbdrag(ByVal HorizontalChange As Double, ByVal VerticalChange As Double)
        Select Case Me.HorizontalAlignment
            Case Windows.HorizontalAlignment.Center
                If Double.IsNaN(Width) Then
                    Width = ActualWidth
                End If
                Width += HorizontalChange

            Case Windows.HorizontalAlignment.Left
                Margin = New Thickness(Margin.Left, Margin.Top, 0.0, Margin.Bottom)
                If Double.IsNaN(Width) Then
                    Width = ActualWidth
                End If
                Width += HorizontalChange

            Case Windows.HorizontalAlignment.Right
                Margin = New Thickness(Margin.Left, Margin.Top, Margin.Right - HorizontalChange, Margin.Bottom)
                If Double.IsNaN(Width) Then
                    Width = ActualWidth
                End If
                Width += HorizontalChange

            Case Windows.HorizontalAlignment.Stretch
                Margin = New Thickness(Margin.Left, Margin.Top, Margin.Right - HorizontalChange, Margin.Bottom)

        End Select
    End Sub

    Private Sub ccthumbdrag(ByVal HorizontalChange As Double, ByVal VerticalChange As Double)
        Select Case Me.HorizontalAlignment
            Case Windows.HorizontalAlignment.Center
                Margin = New Thickness(Margin.Left + HorizontalChange / 2.0, Margin.Top, Margin.Right - HorizontalChange / 2.0, Margin.Bottom)

            Case Windows.HorizontalAlignment.Left
                Margin = New Thickness(Margin.Left + HorizontalChange, Margin.Top, Margin.Right, Margin.Bottom)

            Case Windows.HorizontalAlignment.Right
                Margin = New Thickness(Margin.Left, Margin.Top, Margin.Right - HorizontalChange, Margin.Bottom)

            Case Windows.HorizontalAlignment.Stretch
                Margin = New Thickness(Margin.Left + HorizontalChange, Margin.Top, Margin.Right - HorizontalChange, Margin.Bottom)

        End Select


        Select Case Me.VerticalAlignment
            Case Windows.VerticalAlignment.Center
                Margin = New Thickness(Margin.Left, Margin.Top + VerticalChange / 2.0, Margin.Right, Margin.Bottom - VerticalChange / 2.0)

            Case Windows.VerticalAlignment.Top
                Margin = New Thickness(Margin.Left, Margin.Top + VerticalChange, Margin.Right, Margin.Bottom)

            Case Windows.VerticalAlignment.Bottom
                Margin = New Thickness(Margin.Left, Margin.Top, Margin.Right, Margin.Bottom - VerticalChange)

            Case Windows.VerticalAlignment.Stretch
                Margin = New Thickness(Margin.Left, Margin.Top + VerticalChange, Margin.Right, Margin.Bottom - VerticalChange)

        End Select


    End Sub

    Private Sub rotarrowthumbdrag(ByVal HorizontalChange As Double, ByVal VerticalChange As Double)
        Dim angle = Math.Atan2(VerticalChange, HorizontalChange)

        Dim rt = TryCast(Me.RenderTransform, System.Windows.Media.RotateTransform)

        If rt Is Nothing Then
            Me.RenderTransform = New System.Windows.Media.RotateTransform(-angle)
        Else
            rt.Angle -= angle
        End If

    End Sub

    Private Sub rotcenterthumbdrag(ByVal HorizontalChange As Double, ByVal VerticalChange As Double)
        rotcanvas.Margin = New Thickness(rotcanvas.Margin.Left + HorizontalChange, rotcanvas.Margin.Top + VerticalChange, Margin.Right, Margin.Bottom)

        Dim pt = rotcanvas.TranslatePoint(New Point(0.0, 0.0), Me)

        Me.RenderTransformOrigin = New Point(pt.X / Me.ActualWidth, pt.Y / Me.ActualHeight)
    End Sub

    Private Sub EditZone_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseDoubleClick

        'If Keyboard.Modifiers = ModifierKeys.Control Then

        'Dim r = VisualTreeHelper.HitTest(Me, e.GetPosition(Me))

        Dim ll As New ArrayList()

        Dim filterCallback = Function(p As DependencyObject) As HitTestFilterBehavior
                                 Return HitTestFilterBehavior.Continue
                             End Function

        Dim resultCallback = Function(p As HitTestResult) As HitTestResultBehavior
                                 ll.Add(p)
                                 Return HitTestResultBehavior.Continue
                             End Function

        Dim param = New PointHitTestParameters(e.GetPosition(Me))

        VisualTreeHelper.HitTest(Me, filterCallback, resultCallback, param)

        Dim o = 1
        'End If


    End Sub

    Private Sub MenuItem_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Try

            Dim zone As EditZone = Me.Clone()

            Controls.Grid.SetColumn(zone, 0)
            Controls.Grid.SetColumnSpan(zone, 1)
            Controls.Grid.SetRow(zone, 0)
            Controls.Grid.SetRowSpan(zone, 1)

            zone.DataContext = Me.DataContext
            CType(Me.Parent, Windows.Controls.Grid).Children.Add(zone)
            '     Dim o = DataContext.GraphDefinition.DetailInstance.Clone()

        Catch ex As Exception
            Dim o = 1
        End Try
    End Sub

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Return New EditZone() With {
            .CornerRadius = Me.CornerRadius,
            .Background = Me.Background,
            .BorderSize = Me.BorderSize,
            .BorderBrush = Me.BorderBrush,
            .Margin = Me.Margin,
            .HorizontalAlignment = Me.HorizontalAlignment,
            .VerticalAlignment = Me.VerticalAlignment,
            .Height = Me.Height,
            .Width = Me.Width,
            .RenderTransform = Me.RenderTransform.Clone()
        }
    End Function
End Class

Public Class ColorBrushConverter
    Implements IValueConverter


    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Try
            Return New Media.SolidColorBrush(value)
        Catch ex As Exception
            Return New Media.SolidColorBrush(Media.Colors.Black)
        End Try
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Try
            Return CType(value, Media.SolidColorBrush).Color
        Catch ex As Exception
            Return Media.Colors.Black
        End Try
    End Function

End Class
Public Class BrushColorConverter
    Implements IValueConverter


    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Try
            Return CType(value, Media.SolidColorBrush).Color
        Catch ex As Exception
            Return Media.Colors.Black
        End Try
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Try
            Return New Media.SolidColorBrush(value)
        Catch ex As Exception
            Return New Media.SolidColorBrush(Media.Colors.Black)
        End Try
    End Function

End Class
Public Class DoubleThicknessConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Return New Thickness(value)
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class
Public Class DoubleCornerRadiusConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Return New CornerRadius(value)
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class
Public Class ObjectVerticalAlignmentConverter
    Implements IValueConverter


    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Try
            If value.GetType() Is GetType(VerticalAlignment) Then
                Return CInt(value)
            End If
            Return CType([Enum].ToObject(GetType(VerticalAlignment), value), VerticalAlignment)
        Catch ex As Exception
            Return VerticalAlignment.Stretch
        End Try
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Try
            If value.GetType() Is GetType(Integer) Then
                Return CType([Enum].ToObject(GetType(VerticalAlignment), value), VerticalAlignment)
            End If
            Return CType([Enum].ToObject(GetType(VerticalAlignment), value), VerticalAlignment)
        Catch ex As Exception
            Return VerticalAlignment.Stretch
        End Try
    End Function
End Class
Public Class ObjectHorizontalAlignmentConverter
    Implements IValueConverter


    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Try
            If value.GetType() Is GetType(HorizontalAlignment) Then
                Return CInt(value)
            End If
            Return CType([Enum].ToObject(GetType(HorizontalAlignment), value), HorizontalAlignment)
        Catch ex As Exception
            Return HorizontalAlignment.Stretch
        End Try
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Try
            If value.GetType() Is GetType(Integer) Then
                Return CType([Enum].ToObject(GetType(HorizontalAlignment), value), HorizontalAlignment)
            End If
            Return CType([Enum].ToObject(GetType(HorizontalAlignment), value), HorizontalAlignment)
        Catch ex As Exception
            Return HorizontalAlignment.Stretch
        End Try
    End Function
End Class

Public NotInheritable Class EditZoneFacade

    Private brother As EditZone

    Public Sub New(ByVal brother As EditZone)
        MyBase.New()
        Me.brother = brother
    End Sub
    Public Property Width() As Double
        Get
            Return Me.brother.Width
        End Get
        Set(ByVal value As Double)
            Dim urtoken = New Common.UndoRedoToken()
            Dim old = Me.brother.Width
            urtoken.Display = "Modifier la largeur"
            urtoken.UndoMethod = Sub(obj As Object) Me.brother.Width = old
            urtoken.RedoMethod = Sub(obj As Object) Me.brother.Width = value
            ModuleIndicateurs.AppInstance.GetService(Of Common.IUndoRedoService)().Push(urtoken)
            Me.brother.Width = value
        End Set
    End Property

    Public Property Height() As Double
        Get
            Return Me.brother.Height
        End Get
        Set(ByVal value As Double)
            Dim urtoken = New Common.UndoRedoToken()
            Dim old = Me.brother.Height
            urtoken.Display = "Modifier la hauteur"
            urtoken.UndoMethod = Sub(obj As Object) Me.brother.Height = old
            urtoken.RedoMethod = Sub(obj As Object) Me.brother.Height = value
            ModuleIndicateurs.AppInstance.GetService(Of Common.IUndoRedoService)().Push(urtoken)
            Me.brother.Height = value
        End Set
    End Property

    Public Property HorizontalAlignment() As System.Windows.HorizontalAlignment
        Get
            Return Me.brother.HorizontalAlignment
        End Get
        Set(ByVal value As System.Windows.HorizontalAlignment)
            Dim urtoken = New Common.UndoRedoToken()
            Dim old = Me.brother.HorizontalAlignment
            urtoken.Display = "Modifier l'alignement horizontal"
            urtoken.UndoMethod = Sub(obj As Object) Me.brother.HorizontalAlignment = old
            urtoken.RedoMethod = Sub(obj As Object) Me.brother.HorizontalAlignment = value
            ModuleIndicateurs.AppInstance.GetService(Of Common.IUndoRedoService)().Push(urtoken)
            Me.brother.HorizontalAlignment = value

            If value = HorizontalAlignment.Stretch Then
                brother.Width = Double.NaN
            End If
        End Set
    End Property

    Public Property VerticalAlignment() As System.Windows.VerticalAlignment
        Get
            Return Me.brother.VerticalAlignment
        End Get
        Set(ByVal value As System.Windows.VerticalAlignment)
            Dim urtoken = New Common.UndoRedoToken()
            Dim old = Me.brother.VerticalAlignment
            urtoken.Display = "Modifier l'alignement vertical"
            urtoken.UndoMethod = Sub(obj As Object) Me.brother.VerticalAlignment = old
            urtoken.RedoMethod = Sub(obj As Object) Me.brother.VerticalAlignment = value
            ModuleIndicateurs.AppInstance.GetService(Of Common.IUndoRedoService)().Push(urtoken)
            Me.brother.VerticalAlignment = value

            If value = VerticalAlignment.Stretch Then
                brother.Height = Double.NaN
            End If
        End Set
    End Property

    Public Property Margin() As System.Windows.Thickness
        Get
            Return Me.brother.Margin
        End Get
        Set(ByVal value As System.Windows.Thickness)
            Dim urtoken = New Common.UndoRedoToken()
            Dim old = Me.brother.Margin
            urtoken.Display = "Modifier la marge"
            urtoken.UndoMethod = Sub(obj As Object) Me.brother.Margin = old
            urtoken.RedoMethod = Sub(obj As Object) Me.brother.Margin = value
            ModuleIndicateurs.AppInstance.GetService(Of Common.IUndoRedoService)().Push(urtoken)
            Me.brother.Margin = value
        End Set
    End Property

    Public Property MarginTop() As Double
        Get
            Return Me.brother.Margin.Top
        End Get
        Set(ByVal value As Double)
            Margin = New Thickness(Me.brother.Margin.Left, value, Me.brother.Margin.Right, Me.brother.Margin.Bottom)
        End Set
    End Property

    Public Property MarginLeft() As Double
        Get
            Return Me.brother.Margin.Left
        End Get
        Set(ByVal value As Double)
            Margin = New Thickness(value, Me.brother.Margin.Top, Me.brother.Margin.Right, Me.brother.Margin.Bottom)
        End Set
    End Property

    Public Property MarginBottom() As Double
        Get
            Return Me.brother.Margin.Bottom
        End Get
        Set(ByVal value As Double)
            Margin = New Thickness(Me.brother.Margin.Left, Me.brother.Margin.Top, Me.brother.Margin.Right, value)
        End Set
    End Property

    Public Property MarginRight() As Double
        Get
            Return Me.brother.Margin.Right
        End Get
        Set(ByVal value As Double)
            Margin = New Thickness(Me.brother.Margin.Left, Me.brother.Margin.Top, value, Me.brother.Margin.Bottom)
        End Set
    End Property

    Public Property BorderBrush() As System.Windows.Media.Brush
        Get
            Return Me.brother.BorderBrush
        End Get
        Set(ByVal value As System.Windows.Media.Brush)
            Me.brother.BorderBrush = value
        End Set
    End Property

    Public Property BorderSize() As Double
        Get
            Return Me.brother.BorderSize
        End Get
        Set(ByVal value As Double)
            Dim urtoken = New Common.UndoRedoToken()
            Dim old = Me.brother.BorderSize
            urtoken.Display = "Modifier l'épaisseur de la bordure"
            urtoken.UndoMethod = Sub(obj As Object) Me.brother.BorderSize = old
            urtoken.RedoMethod = Sub(obj As Object) Me.brother.BorderSize = value
            ModuleIndicateurs.AppInstance.GetService(Of Common.IUndoRedoService)().Push(urtoken)
            Me.brother.BorderSize = value
        End Set
    End Property

    Public Property Background() As System.Windows.Media.Brush
        Get
            Return Me.brother.Background
        End Get
        Set(ByVal value As System.Windows.Media.Brush)
            Me.brother.Background = value
        End Set
    End Property

    Public Property CornerRadius As Double
        Get
            Return brother.CornerRadius
        End Get
        Set(ByVal value As Double)
            Dim urtoken = New Common.UndoRedoToken()
            Dim old = Me.brother.CornerRadius
            urtoken.Display = "Modifier le rayon  des angles"
            urtoken.UndoMethod = Sub(obj As Object) Me.brother.CornerRadius = old
            urtoken.RedoMethod = Sub(obj As Object) Me.brother.CornerRadius = value
            ModuleIndicateurs.AppInstance.GetService(Of Common.IUndoRedoService)().Push(urtoken)
            brother.CornerRadius = value
        End Set
    End Property

    Public ReadOnly Property Zone As Object
        Get
            Dim o = TryCast(brother.DataContext, VMDashboardDefinitionZone)
            If o IsNot Nothing Then
                If o.GraphDefinition IsNot Nothing Then
                    If o.GraphDefinition.DetailEdit Is Nothing Then
                        o.GraphDefinition.DetailEdit = New VMEditableObject(o.GraphDefinition.DetailInstance)
                    End If
                    Return o.GraphDefinition.DetailEdit
                End If
            End If

            Return Nothing
        End Get
    End Property

    Public Function ToXElement(ByVal options As Object) As XElement
        Dim x = <EditZone
                    Width=<%= Width %>
                    Height=<%= Height %>
                    HorizontalAlignment=<%= HorizontalAlignment %>
                    VerticalAlignment=<%= VerticalAlignment %>
                    Margin=<%= Margin %>
                    BorderBrush=<%= BorderBrush %>
                    BorderSize=<%= BorderSize %>
                    Background=<%= Background %>
                    CornerRadius=<%= CornerRadius %>>

                    <Detail>

                    </Detail>
                </EditZone>

        Return x
    End Function

    Public Sub FromXElement(ByVal x As XElement)
        Dim cd = Function(s As String) Double.Parse(s, Globalization.CultureInfo.InvariantCulture)
        Dim cc = Function(s As String) If(String.IsNullOrEmpty(s), Nothing, (New Windows.Media.BrushConverter()).ConvertFromString(s))
        Dim ct = Function(s As String) (New Windows.ThicknessConverter()).ConvertFromInvariantString(s)


        Width = cd(x.@Width)
        Height = cd(x.@Height)
        HorizontalAlignment = [Enum].Parse(GetType(HorizontalAlignment), x.@HorizontalAlignment)
        VerticalAlignment = [Enum].Parse(GetType(VerticalAlignment), x.@VerticalAlignment)
        Margin = ct(x.@Margin)
        BorderBrush = cc(x.@BorderBrush)
        BorderSize = cd(x.@BorderSize)
        Background = cc(x.@Background)
        CornerRadius = cd(x.@CornerRadius)
    End Sub
End Class



